
if ( Skt.coupling.enabled ) {
	
	Skt.coupling.activityAdapter = new ClientAdapter(Skt.coupling.cosServer);
	Skt.coupling.activityAdapter.joinSession( "subjectVersion" + Skt.subjectVersion.id + "-activity" + Skt.activity.id );
	
	Skt.coupling.personalAdapter = new ClientAdapter(Skt.coupling.cosServer);
	Skt.coupling.personalAdapter.joinSession("user" + Skt.user.id + "-subjectVersion" + Skt.subjectVersion.id + "-activity" + Skt.activity.id );
	
	Skt.coupling.sketchpadAdapter = new ClientAdapter(Skt.coupling.cosServer);
	Skt.coupling.sketchpadAdapter.joinSession("sketchpad");
	
}

Skt.sketchpad = new L.Sketchpad(
	$("#editor"), 
	{ 
		width: 1024, 
		height: 672 
	}
);



Skt.model = new L.Model(
	{
		subjectVersionId: Skt.subjectVersion.id,
		activityId: Skt.activity.id,
		userId: Skt.user.id
	},
	Skt.config,
	Skt.coupling
);	

Skt.sketchpad.setModel(Skt.model);

if ( Skt.config.USE_UI ) {
	
	Skt.sketchpad.on('currentCanvasChange', Skt.handlers.currentCanvasChangeHandler , null);
	
	Skt.user_list = new L.UserList({
		carriedId: "userlist-" + Skt.subjectVersion.id + "-" + Skt.activity.id,
		adapter: Skt.coupling.activityAdapter,
		enabled: Skt.coupling.enabled
	});
	
	Skt.user_list.on('userAction', Skt.handlers.userListHandler, null);	
	Skt.user_list.on('requestIssued', Skt.handlers.requestIssuedHandler, null);	
	Skt.user_list.on('requestDismissed', Skt.handlers.requestDismissedHandler, null);
	
	Skt.user_list.addUser(Skt.user.id, Skt.user.name, Skt.user.lastname, Skt.user.type);
	Skt.user_list.changeInstances(Skt.user.id, 1);
	
	Skt.groupsManager = new L.GroupsManager({
		enabled: Skt.coupling.enabled,
		adapter: Skt.coupling.activityAdapter,
		carriedId: "groupsmanager"
	});
	
	Skt.groupsManager.on('groupEvent', Skt.handlers.groupEventHandler, null);
	Skt.groupsManager.on('invitationEvent', Skt.handlers.invitationHandler, null);
	
	Skt.tvManager = new L.TVManager({
		enabled: Skt.coupling.enabled,
		adapter: Skt.coupling.sketchpadAdapter,
		carriedId: "tvmanager"
	});

	Skt.tvManager.on('groupJoinRequest', Skt.handlers.tvGroupJoinHandler, null);
	if ( Skt.user.type == "tv" ) {
		Skt.tvManager.on('roomFocusRequest', Skt.handlers.tvRoomFocusHandler, null);
		Skt.tvManager.on('followingJoinRequest', Skt.handlers.followingJoinHandler, null);
	}
	
	Skt.teacherMonitor = new L.TeacherMonitor({
		carriedId: "teachermonitor",
		adapter: Skt.coupling.activityAdapter,
		enabled: Skt.coupling.enabled
	});
	
	if ( Skt.user.type == 'teacher' ) {
		Skt.sketchpad.on('currentCanvasChange', Skt.teacherMonitor.handleCurrentCanvasChange, Skt.teacherMonitor);
	} else {
		Skt.teacherMonitor.on('followingEnabledChanged', Skt.handlers.handleFollowingEnabledChanged, null);
		Skt.teacherMonitor.on('teacherRoomChanged', Skt.handlers.handleTeacherRoomChanged, null);
	}
	
}

Skt.sketchpad.tool(new L.PenTool(Skt.sketchpad));
		
Skt.isMobile = function() { 
	return navigator.userAgent.match(/Android/i) 
		|| navigator.userAgent.match(/iPhone/i)
		|| navigator.userAgent.match(/iPad/i)
		|| navigator.userAgent.match(/iPod/i);
};

Skt.delete_action = 0;
Skt.editingEnabled = true;

	

